<template>
  <div class="login">
    <div class="content">
      <div class="login-content">
        <div class="banner-box" @click="to_home"></div>
        <div class="login-box">
          <div class="logo"></div>
          <input v-model="user_info.username" @keyup.enter="onSubmit" type="text" placeholder="账号">
          <input v-model="user_info.password" @keyup.enter="onSubmit" type="password" placeholder="密码">
          <button class="login-btn" @click="onSubmit">登录</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {loginUser} from "@/js/global_axios";
import ElementUI from "element-ui";

export default {
  name: "Login",
  data() {
    return {
      labelPosition: 'right',
      user_info: {
        username: '',
        password: '',
      }
    };
  },
  methods: {
    onSubmit() {
      let params = {}
      params['user_info'] = this.user_info
      loginUser(params).then(response => {
        if (response.data.status === 'success') {
          ElementUI.Message({
            dangerouslyUseHTMLString: true,
            message: '<div><p>登录成功！</p><p><i class="el-icon-loading"></i>正在前往主页...</p></div>',
            type: 'success'
          });
          setTimeout(function () {
            window.location.href = '/'
          }, 1500)
        } else {
          ElementUI.Message({
            showClose: true,
            type: 'error',
            message: response.data.message,
          })
        }
      })
    },
    clear() {
      this.user_info.username = ''
      this.user_info.password = ''
    },
    to_home () {
      window.location.href = '/'
    }
  }
}
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
}

.content {
  width: 100vw;
  height: 100vh;
  /* background-color: aqua; */
  background: url('../assets/login_img.jpg') no-repeat;
  background-size: cover;
  display: flex;
  justify-content: center;
  align-items: center;
}

.login-content {
  position: relative;
  width: 800px;
  height: 360px;
  background-color: rgba(172, 103, 30, 0.29);
  border-radius: 30px;
  padding: 15px;
}

.banner-box {
  display: inline-block;
  width: 500px;
  height: 100%;
  background: url('../assets/login_img.jpg') no-repeat;
  background-size: cover;
  border-radius: 20px 0 0 20px;
}
.banner-box:hover {
  padding: 1px;
}

.login-box {
  width: 330px;
  height: 100%;
  position: absolute;
  top: 0;
  right: 0;
  border-radius: 0 30px 30px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.login-box > h1 {
  font-size: 36px;
  margin: 60px 0;
  color: #fff;
}

.login-box > input {
  margin-bottom: 20px;
  width: 200px;
  height: 36px;
  padding: 0 20px;
  border-radius: 36px;
  border: none;
  outline: none;
  font-size: 18px;
  background: rgba(202, 199, 201, 0.5);
}

input::-webkit-input-placeholder {
  color: #e2e2e2;
}

.logo {
  width: 150px;
  height: 150px;
  margin: 20px auto 20px;
  background-color: #f8f2f2;
  border-radius: 50%;
  background: url("../assets/head.jpg");
  background-repeat: no-repeat;
  background-size: 150px 150px;
}

.login-btn {
  margin-top: 10px;
  width: 240px;
  height: 40px;
  background-color: rgba(87, 99, 113, 0.5);
  border: none;
  border-radius: 40px;
  color: #fff;
  font-size: 18px;
}

.login-btn:hover {
  background-color: rgba(68, 72, 78, 0.8);
  color: #fff;
  cursor: pointer;
}

@media screen and (max-width: 900px) {
  .login-content {
    margin: 0 30px;
  }

  .banner-box {
    border-radius: 20px;
  }

  .login-box {
    background-color: rgba(52, 0, 73, 0.5);
  }
}

@media screen and (max-width: 600px) {
  .content {
    background: url('../assets/login_img.jpg') no-repeat center;
  }

  .login-content {
    background-color: transparent;
  }

  .banner-box {
    display: none;
  }

  .login-box {
    position: initial;
    margin: -40px auto;
    background-color: transparent;
  }
}
</style>